#ifndef JTHREADPOOL_H
#define JTHREADPOOL_H

#include "jthreadpool_global.h"
#include "jrunnable.h"

// - class JThreadPool -

class JThreadPoolPrivate;
class QThreadPool;

/**
 * @brief The JThreadPool class
 */
class JTHREADPOOL_EXPORT JThreadPool
{
public:
    /**
     * @brief JThreadPool
     */
    JThreadPool();
    ~JThreadPool();

    /**
     * @brief globalInstance
     * @return
     */
    static JThreadPool globalInstance();

    /**
     * @brief start
     * @param runnable
     * @param priority
     */
    void start(JRunnable *runnable, int priority = 0);

    /**
     * @brief tryStart
     * @param runnable
     * @return
     */
    bool tryStart(JRunnable *runnable);

    /**
     * @brief expiryTimeout
     * @return
     */
    int expiryTimeout() const;

    /**
     * @brief setExpiryTimeout
     * @param expiryTimeout
     */
    void setExpiryTimeout(int expiryTimeout);

    /**
     * @brief maxThreadCount
     * @return
     */
    int maxThreadCount() const;

    /**
     * @brief setMaxThreadCount
     * @param maxThreadCount
     */
    void setMaxThreadCount(int maxThreadCount);

    /**
     * @brief activeThreadCount
     * @return
     */
    int activeThreadCount() const;

    /**
     * @brief reserveThread
     */
    void reserveThread();

    /**
     * @brief releaseThread
     */
    void releaseThread();

    /**
     * @brief waitForDone
     */
    void waitForDone();

    /**
     * @brief waitForDone
     * @param msecs
     * @return
     */
    bool waitForDone(int msecs);

    /**
     * @brief JThreadPool
     * @param other
     */
    JThreadPool(QThreadPool *other);

private:
    J_DISABLE_COPY(JThreadPool)
    J_DECLARE_PRIVATE(JThreadPool)
    friend class JFutureInterfaceBase;
};

#endif  // JTHREADPOOL_H
